<template>
  <div class="page_hasWorked">

    <com-top-nav-bar
      :topNavBarObj="topNavBarObj"
      @toGetKeywordOrDateStr="getKeyWordOrDateStr"
    />

    <div class="jobArr" v-if="hasWorkedList.length">
      <job-item-for-work
        v-for="(item, index) in hasWorkedList"
        :key="item.id"
        :id="item.id"
        :serchType="1"
        :keyWord="'hasWorkedList'"
        :jobItem="item"
      ></job-item-for-work>

      <van-pagination
        v-model="querySearchObj.pageIndex"
        :total-items="total"
        :items-per-page="querySearchObj.pageSize"
        @change="getPaginationValue_hasWord"
        force-ellipses
      >
        <template #prev-text>
          <van-icon name="arrow-left" />
        </template>
        <template #next-text>
          <van-icon name="arrow" />
        </template>
        <template #page="{ text }">{{ text }}</template>
      </van-pagination>
    </div>

    <van-divider style="margin-top: 80px" v-else>暂无记录</van-divider>



  </div>
</template>

<script>
import jobItemForWork from "./jobItemForWork";
import comTopNavBar from "../../components/comTopNavBar";


export default {
  name: 'hasWorkedList',
  components: {
    comTopNavBar,
    jobItemForWork,
  },
  data() {
    return {
      topNavBarObj: {
        title: '已工作',
        searchPlaceholder: '搜索关键字：企业名称、工作名字',
        dateLabel: '已工作',
        pathForLeft: '',
      },
      hasWorkedList: [],
      total: 0,
      querySearchObj: {
        pageIndex: 1,
        pageSize: 10,
        keyword: '',
        // todo 替换 工作时间 还是集合一个字段了？
        worktime: '',
      },
    }
  },
   created() {
     this._getWorkList(this.querySearchObj);
  },
  methods: {
    async _getWorkList(params){
      let userInfo = JSON.parse(localStorage.getItem('userInfo'))
      const resp = await this.$api.job.getJobBeenWorking({
        UserId: userInfo.id,
        ...params
      });
      if (resp.code === 200){
        this.hasWorkedList = resp.data.jobs;
        this.total = resp.data.count || 0
      }
    },

    toJobDetailPage(id) {
      console.log('已工作---子到父---进入详情', id)
      this.$router.push({
        path: `/jobDetail/${id}`
      })
    },



    getPaginationValue_hasWord(val){
      console.log('翻页', val);
      // 指定页
      Object.assign(this.querySearchObj, {pageIndex: val})
      this._getWorkList(this.querySearchObj)
    },

    getKeyWordOrDateStr(val){
      const obj = {
        pageIndex: 1,
        keyword: val.keyword,
        worktime: val.date,
      }
      Object.assign(this.querySearchObj, obj)
      this._getWorkList(this.querySearchObj)
    },
  }
}
</script>

<style lang="scss" scoped>
.page_hasWorked {
  width: 100%;
  .jobArr {
    & > div:last-child {
      border-bottom: 0.6px solid #e6e6e6;
    }
  }
}
</style>
